<template>
  <section class="container">
    <div>
        <el-form ref="login" :model="form" label-position="right">
            <el-form-item label="手机号">
                <el-input v-model="form.account"></el-input>
            </el-form-item>
            <el-form-item label="密码">
                <el-input type="password" v-model="form.password"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">登录</el-button>
                <el-button @click="$router.back(-1)">退出</el-button>
            </el-form-item>
        </el-form>   
    </div>
  </section>
</template>

<script>
import axios from 'axios'

export default {
    data() {
        return {
            form : {
                account:'guest',
                password:'hao123'
            }
        }
    },
    asyncData ({ route}) {
        return {
            
        }
    },
    methods:{
        async onSubmit(){
            let { data } = await axios.post(`/proxy/auth/login`,this.form)
            if(data.status==1){
                this.$store.dispatch('login',data.result) 
                this.$message({
                    message: '登录成功',
                    type: 'success'
                });
                this.$router.push({ path: '/user' })
            }else{
                this.$message({
                    message: '登录失败',
                    type: 'warning'
                });
            }
        }
        
    }
    
  
}
</script>